package com.dd.mapper;

import com.dd.pojo.Order;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface OrderMaper {
 @Insert("insert into orders values(#{uuid},#{price},#{address_id},#{costs},#{number})")
    public int save(Order order);

 @Select("select * from orders where address_id=#{id}")
 public Order findByAddressId(Integer id);

 @Update("update orders set price=#{price},costs=#{costs},number=#{number} where uuid=#{uuid}")
    public void upte(Order order);


 @Select("SELECT o.`uuid`,o.`price`,o.`costs`,o.number,o.`address_id`,a.`costs` AS totals\n" +
         "FROM orders o\n" +
         "         LEFT JOIN userorder u\n" +
         "          ON u.`order_id`=o.`uuid`\n" +
         "          LEFT JOIN address a \n" +
         "          ON a.`id`=o.`address_id`          \n" +
         "           WHERE u.user_id=#{id}")
    List<Order> findAllById(Integer id);


 @Select("SELECT \n" +
         "   o.`uuid`,a.`costs` AS totals,o.`costs`,o.number\n" +
         " FROM  \n" +
         "orders o \n" +
         "LEFT JOIN address a ON o.`address_id`=a.`id` \n" +
         "WHERE a.`user_id`=#{id}")
 public List<Order> findAllUser(Integer id);
}
